home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: genew@mindlink.bc.ca (Gene Wirchenko)
- Newsgroups: comp.lang.c
- Subject: Re: division problem
- Date: Mon, 29 Jan 1996 18:42:26 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4ej4ha$66@fountain.mindlink.net>
- References: <31097D77.11AA@rain.org> <26JAN199622082450@erich.triumf.ca> <4eh246$u6h@airdmhor.gen.nz>
- NNTP-Posting-Host: line038.nwm.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- gumboot@airdmhor.gen.nz (Simon Hosie) wrote:
-
- >P.Bennett:
- >> In order to make it work, you could do:
- >> celsius = (int)((5.0/9.0) * (fahrenheit - 32))
- >> The 5.0/9.0 give a meaningful result, and force the multiplication to be done
- >> with floats. The (int) will convert the result back to an int.
-
- > That's disgusting!
-
- >celcius = (fahrenheit - 32) * 5 / 9;
-
- That's disgusting <g> as it doesn't round. Try it with 39 deg F:
- (39-32)*5/9 ::= 7*5/9 ::= 35/9 ::= 3
- but the actual value is 3.8... i.e. nearly 4. If you must int, 4
- would be a better answer.
-
- Sincerely,
-
- Gene Wirchenko
-
- C Pronunciation Guide:
- y=x++; "wye equals ex plus plus semicolon"
- x=x++; "ex equals ex doublecross semicolon"
-
-